<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>积分红包规则</title>
    <link rel="stylesheet" type="text/css" th:href="@{/js/layui/css/layui.css}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/style.css/}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/my.css/}" media="all">

</head>
<body class="body">
<script type="text/html" id="topOperate">
    <div class="my-btn-box layui-form">
      <span class="fl">
      </span>
    </div>
</script>

<!-- 表格 -->
<div id="dateTable" lay-filter="event"></div>
<div class="height50"></div>
<script th:src="@{/js/layui/layui.js}"></script>
<script th:src="@{/js/fyn/index.js}"></script>
<script th:src="@{/js/fyn/my.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_comm.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_table.js}"></script>
<script type="text/javascript" th:inline="javascript">

    // layui方法
    layui.use(['table', 'form', 'laypage', 'layer', 'vip_table', 'laydate'], function () {

        // 操作对象
        var form = layui.form
            , table = layui.table
            , layer = layui.layer
            , vipTable = layui.vip_table
            , laydate = layui.laydate
            , $ = layui.jquery;

        //常规用法
        laydate.render({
            elem: '#startTime'
        });

        //常规用法
        laydate.render({
            elem: '#endTime'
        });

        laydate.render({
            elem: '#limitTime',
            type: 'datetime'
        });

        var inter = null;

        form.on('switch(close)', function (data) {

            if (this.checked) {
                inter = setInterval(function () {
                    tableIns.reload(getJson());
                }, 10000);
            } else {
                clearInterval(inter);
            }

        });


        // 表格渲染
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , height: "full"    //容器高度
            , skin: 'line'
            , even: 'true'
            , cols: [[                  //标题栏
                {
                    field: 'id', title: 'id', width: '5%', sort: true, align: 'center', templet: function (d) {
                        return d.id;
                    }

                }
                , {
                    field: 'level', title: '积分等级', width: '10%', align: 'center', templet: function (d) {
                        return d.level;
                    }
                }
                , {
                    field: 'totalMoney', title: '总金额', width: '5%', align: 'center', templet: function (d) {
                        return d.totalMoney;
                    }
                }
                , {
                    field: 'num', title: '份数', width: '10%', align: 'center', templet: function (d) {
                        return d.num;
                    }
                },
                {
                    field: 'minMoney', title: '最小领取金额', width: '10%', align: 'center', templet: function (d) {
                        return d.minMoney;
                    }
                },
                {
                    field: 'maxMoney', title: '最大领取金额', width: '10%', align: 'center', templet: function (d) {
                        return d.maxMoney;
                    }
                },
                {
                    field: 'forceValid', title: '强制更新', width: "5%", event: 'setForceValid', templet: function (d) {
                        return d.forceValid == 1 ? "强制" : "不强制";
                    }
                }
                , {
                    field: 'ctime',
                    align: 'center',
                    title: '发送时间',
                    sort: true,
                    width: "15%",
                    templet: function (d) {
                        return new Date(d.ctime).Format("yyyy-MM-dd hh:mm:ss");
                    }
                }
                , {
                    title: '操作', align: 'center', templet: function (d) {

                        var html = "<i class=\"layui-icon layui-icon-edit\" title=\"编辑\" style=\"cursor: pointer\" lay-event=\"edit\"></i>";
                        return html;

                    }
                } //这里的toolbar值是模板元素的选择器
            ]]
            , id: 'dataCheck'
            , url: [[${basePath}]] + '/packet/integral/rule/list'
            , method: 'get'
            , page: true
            , limits: [10, 30, 60, 90, 150, 300]
            , toolbar: '#topOperate'
            , limit: 10 //默认采用0
            , loading: true
            , where: getJson()
            , done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                $("td[data-field='content']").each(function () {
                    $(this).find(".layui-table-cell").removeClass('layui-table-cell');
                });
            }
        });


        //头工具栏事件
        table.on('toolbar(event)', function (obj) {
            switch (obj.event) {
                case 'toSave':
                    layer.open({
                        type: 2,
                        title: '规则增加',
                        shadeClose: true,
                        shade: 0.2,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['650px', '550px'],
                        content: [[${basePath}]] + '/packet/integral/rule/save/index'
                    });
                    break;
            }
        });

        table.on('tool(event)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {

                layer.open({
                    type: 2,
                    title: '规则修改',
                    shadeClose: true,
                    shade: 0.2,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['650px', '550px'],
                    content: [[${basePath}]] + '/packet/integral/rule/save/index?id=' + data.id
                });

            }

            if (obj.event === 'setForceValid') {
                $.ajax({
                    type: "post",
                    url: [[${basePath}]] + "/packet/integral/rule/force/save",
                    data: {forceValid: data.forceValid == 0 ? 1 : 0, id: data.id},
                    success: function (res) {
                        if (res.success) {
                            layer.msg("操作完成", {icon: 1});
                            setTimeout(function () {

                            }, 1500);
                            tableIns.reload();
                        }
                    }
                });
            }
            if (obj.event === 'setStatus') {
                $.ajax({
                    type: "post",
                    url: [[${basePath}]] + "/packet/integral/rule/status/save",
                    data: {status: data.status == 0 ? 1 : 0, id: data.id},
                    success: function (res) {
                        if (res.success) {
                            layer.msg("操作完成", {icon: 1});
                            setTimeout(function () {

                            }, 1500);
                            tableIns.reload();
                        }
                    }
                });
            }
        });


        function getJson() {
            return {
                where: {
                    name: $("input[name='name']").val()
                }
            };
        }

    });
</script>

</body>
</html>